pl-hlist
This Rust library provides support for heterogeneous lists (known as HList
s). An HList
is a functional,
tuple-like, strongly-typed data structure that can contain elements of differing types.
There are three layers in this library:
- A basic
HList
data structure consisting ofHCons
andHNil
types. - An
hlist!
macro for constructing anHList
from a series of elements. - An
HListSupport
plugin/attribute that, when declared for a struct, allows for easy conversion of struct instances to/from anHList
representation.
See the next section for more details on usage of these layers.
Usage
Add a dependency to your Cargo.toml
:
[]
= "1.0"
Then, in your crate:
use *;
An HList
can be constructed manually as follows:
let x: = HCons;
The hlist!
macro provides a convenient shorthand for constructing an HList
:
let x: = hlist!;
The custom HListSupport
derive attribute can be applied to a struct declaration to automatically implement support for converting that struct to/from an HList
representation:
let hlist0 = hlist!;
let s = from_hlist;
assert_eq!;
assert_eq!;
let hlist1 = s.into_hlist;
assert_eq!;
License
pl-hlist
is distributed under an MIT license. See LICENSE for more details.